<?php                          
use_javascript('wemTabs.js','last');
use_stylesheet('list.css');
use_helper('toolsbar');
slot('PageTitle',$plant);
slot('Title',$plant);
slot('Toolsbar');
    echo createToolbar();
        echo addButton("Edit", url_for('plant_edit',$plant));
        echo addButton("Delete", url_for('plant_delete',$plant),array('method'=>'delete','confirm' => 'Are you sure? \nBy a click on yes yuo\'re going to completely remove '.$plant.' ?'));
        echo addButton("Add Sub-Plants",url_for('subplant_new',array("plant"=>$plant->getId())));
        echo addButton("Add Devices", url_for('powerdev_new',array("plant"=>$plant->getId())));
    echo endToolbar();
end_slot();
?>

<div id="tabs">
    <ul>
        <li><a href='#tab-info'><span>Plant Info</span></a></li>
        
        <?php if (count($subPlants)>1){
             ?>  <li><a href='#tab-subplants'><span>Sub Plants</span></a></li>
        <?php }?>

        <?php if (count($netDevs)>1){
             ?>  <li><a href='#tab-netDevs'><span>Network Devices</span></a></li>
        <?php }?>

        <?php foreach($devTypes as $type){ ?>      
              <li><a href='#<?php echo "tab-".str_replace(" ", "", $type)?>'><span><?php echo $type?></span></a></li>
        <?php } ?>
        
    </ul>
    
    <div id="tab-info">
          <table id="lista">
             <tbody>
                <tr class="even">
                <th>Code:</th>
                <td><?php echo $plant->getCode() ?></td>
                </tr>
                <tr class="odd">
                <th>Owner:</th>
                <td><a href="<?php echo url_for('client_show',$plant->getClient())?>"><?php echo $plant->getClient()?></td>
                </tr>
                <tr class="even">
                <th>Country:</th>
                <td><?php echo $plant->getCountry() ?></td>
                </tr>
                <tr class="odd">
                <th>City:</th>
                <td><?php echo $plant->getCity() ?></td>
                </tr>
                <tr class="even">
                <th>Location:</th>
                <td><?php echo $plant->getLocation() ?></td>
                </tr>
                <tr class="odd">
                <th>Coordinates:</th>
                <td><?php echo $plant->getCoordinates() ?></td>
                </tr>
                <tr class="even">
                <th>Pm:</th>
                <td><?php echo $plant->getPm() ?></td>
                </tr>
                <tr class="odd">
                <th>Path:</th>
                <td><?php echo $plant->getPath() ?></td>
                </tr>
                <tr class="even">
                <th>Pn:</th>
                <td><?php echo $plant->getPn() ?> kW</td>
                </tr>
                <tr class="odd">
                <th>Type:</th>
                <td><?php echo $plant->getType() ?></td>
                </tr>
                <tr class="even">
                <th>Structure:</th>
                <td><?php echo $plant->getStructure() ?></td>
                </tr>
                <tr class="odd">
                <th>Est rad:</th>
                <td><?php 
                        echo is_null($plant->getEstRad())?"-":$plant->getEstRad()."kWh/mq per year" ?></td>
                </tr>
                <tr class="even">
                <th>Area:</th>
                <td><?php echo is_null($plant->getArea())?"-":$plant->getArea()." mq" ?> </td>
                </tr>
                <tr class="odd">
                <th>Perimeter:</th>
                <td><?php echo is_null($plant->getPerimeter())?"-":$plant->getPerimeter()." m" ?></td>
                </tr>
                <tr class="even">
                <th>Tilt:</th>
                <td><?php echo is_null($plant->getTilt())?"-":$plant->getTilt()." °" ?></td>
                </tr>
                <?php foreach ($plant->getSubcontract() as $key=>$subcontract): 
                    $odd = fmod($key, 2) ? 'even':'odd';?>
                <tr class="<?php echo $odd?>">
                    <th> <?php echo $subcontract->getType() ?>: &nbsp; </th>
                <td><a href="<?php echo url_for('supplier_show',$subcontract->getSupplier())?>"><?php echo $subcontract->getSupplier() ?></a></td>
                </tr>
                <?php endforeach;?>

            </tbody>
        </table>
    </div>
    <?php if (count($subPlants)>1){?>
         <div id="tab-subplants">
            <?php include_partial('subplant/list', array('subPlants' => $subPlants)) ?>
         </div>
    <?php }   ?>
    
        <?php if (count($netDevs)>1){?>
         <div id="tab-netDevs">
             <?php include_partial('network/list', array('netDevs' => $netDevs)) ?>
         </div>
    <?php }   ?>
    
    
    
  <?php 
    $prevType="";
    $monitoredTypes=sfConfig::get("app_monitored_dev_types");
    
    foreach($devs as $key=>$dev){
         $odd = fmod($key, 2) ? 'odd' : 'even';
        if ($prevType<>$dev->getType()){
            $prevType=$dev->getType();
    ?>      
            <div id="tab-<?php echo str_replace(" ", "", $prevType)?>">
                <table id="lista">
                    <thead>
                        <tr>
                            <th>Type</th>
                            <th>SubType</th>
                            <th>Brand</th>
                            <th>Model</th>
                            <th>Serial</th>
                            <th><?php $col=($dev->getQuantity()>1)?"Quantity":"Label";echo $col?></th>
                      <?php if ($dev->getPower()>0){
                            ?><th>Power</th>
                      <?php } ?>
                      <?php
                            if (array_search($dev->getType(), $monitoredTypes)!== false){ ?>
                                <th>Acquisition Syst 1</th>
                                <th>Id 1</th>
                                <th>Acquisition Syst 2</th>
                                <th>Id 2</th>
                      <?php } ?>
                            <th>Note</th>
                        </tr>
                    </thead>
 <?php   }      ?>
                    
                    <tr class="<?php echo $odd?>">
                        <td><a href="<?php echo url_for('powerdev_show',$dev)?>"><?php echo $dev->getType()."   "?></a></td>
                        <td><a href="<?php echo url_for('powerdev_show',$dev)?>"><?php echo $dev->getSubtype()?></td>
                        <td><a href="<?php echo url_for('powerdev_show',$dev)?>"><?php $val=(is_null($dev->getBrand()) or $dev->getBrand()=="")?"-":$dev->getBrand();echo $val?>
                        <td><a href="<?php echo url_for('powerdev_show',$dev)?>"><?php $val=(is_null($dev->getModel()) or $dev->getModel()=="")?"-":$dev->getModel();echo $val?>
                        <td><a href="<?php echo url_for('powerdev_show',$dev)?>"><?php $val=(is_null($dev->getSerial()) or $dev->getSerial()=="")?"-":$dev->getSerial();echo $val?>
                        <td><a href="<?php echo url_for('powerdev_show',$dev)?>"><?php $val=($dev->getQuantity()>1)?$dev->getQuantity():$dev->getLabel();echo $val?></td>
                      <?php if ($dev->getPower()>0){
                            ?><td><?php echo $dev->getPower()."  kW" ?></td>
                      <?php } ?>
                      <?php
                            if (array_search($dev->getType(), $monitoredTypes)!== false){ ?>
                                <td><?php $val=(is_null($dev->getSource()) or $dev->getSource()=="")?"-":$dev->getSource();echo $val?>
                                <td><?php $val=(is_null($dev->getAddress()) or $dev->getAddress()=="")?"-":$dev->getAddress();echo $val?>
                                <td><?php $val=(is_null($dev->getSource2()) or $dev->getSource2()=="")?"-":$dev->getSource2();echo $val?>
                                <td><?php $val=(is_null($dev->getAddress2()) or $dev->getAddress2()=="")?"-":$dev->getAddress2();echo $val?>
                      <?php } ?>
                       <td><?php $val=($dev->getNote()>1)?$dev->getNote():$dev->getNote();echo $val?></td>
                    </tr>  
<?php 
                        

            if ($prevType<>$devs[$key+1]->getType()){
            ?> 
                </table>
              </div>
   <?php    
            }
} ?>
 </div>                   
            

  